class Channel {
	constructor(arg) {
		type: 'Channel'
	}
	// 接收值事件
	eventOn(that, emitName, feedback) {
		// #ifdef APP-NVUE
		const eventChannel = that.$scope.eventChannel; // 兼容APP-NVUE
		// #endif
		// #ifndef APP-NVUE
		const eventChannel = that.getOpenerEventChannel();
		// #endif
		eventChannel.on(emitName, res => {
			feedback(res);
		})
		console.log(emitName, feedback)
	}
	// 发送事件 不跳页面
	eventEmit(that, emitName, data) {
		// #ifdef APP-NVUE
		const eventChannel = that.$scope.eventChannel; // 兼容APP-NVUE
		// #endif
		// #ifndef APP-NVUE
		const eventChannel = that.getOpenerEventChannel();
		// #endif
		eventChannel.emit(emitName, data);
	}
	// 跳转页面并传参
	navigateEmit(url, options = {}) {
		const {
			emitName,
			data,
			eventName,
			callback
		} = options;
		const events = {};
		if (eventName) {
			events[eventName] = (result) => {
				return callback(result);
			}
		}
		uni.navigateTo({
			url: url,
			animationDuration: 400,
			success(res) {
				if (emitName) {
					res.eventChannel.emit(emitName, data);
				}
			},
			events
		})
	}
}

export default Channel
